home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
comm2
/
kms20src.lha
/
KMSC
/
ums2kms.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-16
|
28KB
|
1,020 lines
/**
** UMS2KMS.c
**
** Creates KMS area tree from UMS message base groups.
**
** © Copyright 1994 Thomas Schwarz, Germany
** All Rights Reserved.
**/
// Includes
#include <KMS/KMS.h>
#include <KMS/KMS_devlib.h>
// Defines
// Prototypes
UWORD MyBreak(VOID);
VOID main(UWORD, STRPTR *);
VOID Cleanup(VOID);
BOOL ParseArgs(VOID);
BOOL ReadAreaList(VOID);
BOOL WriteAreaList(VOID);
struct AreaNode *GroupSearch(STRPTR name);
struct AreaNode *AreaSearch(STRPTR name);
VOID CreatePath(struct AreaNode *area);
struct AreaNode *SetArea(UWORD idx);
struct AreaNode *InsertArea(VOID);
VOID Upper(STRPTR string);
VOID Lower(STRPTR string);
VOID ConvertSpaces(STRPTR string);
VOID LinkArea(struct AreaNode *mother, struct AreaNode *newan);
// Global vars
STRPTR Version = "\0$VER: UMS2KMS 1.0 ("__COMMODORE_DATE__")";
struct MinList AreaList;
STRPTR AreaFile = NULL;
STRPTR KMSRoot = NULL;
STRPTR Pattern = NULL;
STRPTR DOSPatt = NULL;
BOOL Force;
TEXT PathString[LEN_KMSPATH+1];
/*********************************
* MyBreak *
*********************************
* I: --- *
* O: 0 *
*********************************/
/// MyBreak
UWORD MyBreak(VOID)
{
return 0;
}
///
/*********************************
* main *
*********************************
* I: argc, argv *
* O: --- *
*********************************/
/// main
VOID main(UWORD argc, STRPTR *argv)
{
UMSAccount *account;
onbreak(MyBreak);
NewList((struct List *)&AreaList);
if (!ParseArgs())
exit(20);
if (!ReadAreaList())
{
Cleanup();
exit(20);
}
if (Pattern)
{
DOSPatt = malloc(strlen(Pattern) * 2 + 2);
if (DOSPatt)
ParsePatternNoCase(Pattern, DOSPatt, strlen(Pattern) * 2 + 2);
else
{
fprintf(stderr, "Error: out of memory!\n");
Cleanup();
exit(20);
}
}
/* System-Login */
TEXT varbuff[32] = "";
TEXT pwbuff[32] = "";
GetVar("KMSMB", varbuff, sizeof(varbuff), NULL);
GetVar("KMSPWD", pwbuff, sizeof(pwbuff), NULL);
if (!(account = UMSRLogin(varbuff, "KMS", pwbuff)))
{
fprintf(stderr, "Error: couldn't log into UMS!\n");
Cleanup();
exit(20);
}
STRPTR group, group2, arg; /* Pointer to group name */
struct AreaNode *apoint, *newapoint, *mother, *root;
/* First create KMS root if not exists */
root = SetArea(1);
if (!root)
{
root = InsertArea();
if (!root)
{
fprintf(stderr, "Error: couldn't create KMS root area!\n");
Cleanup();
UMSLogout(account);
exit(20);
}
strcpy(root->AreaData.Name, "PRIVAT");
strcpy(root->AreaData.Info, "- Private Mail -");
strcpy(root->AreaData.MBName, "");
strcpy(root->AreaData.FilePath, "KMS:Files/");
root->AreaData.Type = ATYPE_PRIVATE;
root->AreaData.ReadLevel = 1;
root->AreaData.WriteLevel = 1;
root->AreaData.EditLevel = 255;
root->AreaData.QuoteStr = 1;
root->AreaData.PQuoteStr = 1;
root->AreaData.ResendStr = 1;
root->AreaData.ForwardStr = 1;
root->AreaData.OriginStr = 1;
root->AreaData.HoldNum = 0;
root->AreaData.HoldDays = 0;
root->AreaData.Mother = 0;
root->AreaData.Daughter = 0;
root->AreaData.Next = 0;
}
/* Main root ok, now create given root for area tree */
if (KMSRoot)
{
ConvertSpaces(KMSRoot);
apoint = AreaSearch(KMSRoot);
if (!apoint)
{
newapoint = InsertArea();
if (!newapoint)
{
fprintf(stderr, "Error: couldn't create given root area!\n");
Cleanup();
UMSLogout(account);
exit(20);
}
strncpy(newapoint->AreaData.Name, KMSRoot, sizeof(newapoint->AreaData.Name)-1);
newapoint->AreaData.Name[sizeof(newapoint->AreaData.Name)-1] = '\0';
Upper(newapoint->AreaData.Name);
strncpy(newapoint->AreaData.Info, KMSRoot, sizeof(newapoint->AreaData.Info)-1);
newapoint->AreaData.Info[sizeof(newapoint->AreaData.Info)-1] = '\0';
strncpy(newapoint->AreaData.MBName, KMSRoot, sizeof(newapoint->AreaData.MBName)-1);
newapoint->AreaData.MBName[sizeof(newapoint->AreaData.MBName)-1] = '\0';
Lower(newapoint->AreaData.MBName);
strcpy(newapoint->AreaData.FilePath, "");
newapoint->AreaData.Type = ATYPE_NEWS;
newapoint->AreaData.ReadLevel = 0;
newapoint->AreaData.WriteLevel = 0;
newapoint->AreaData.EditLevel = 255;
newapoint->AreaData.QuoteStr = 1;
newapoint->AreaData.PQuoteStr = 1;
newapoint->AreaData.ResendStr = 1;
newapoint->AreaData.ForwardStr = 1;
newapoint->AreaData.OriginStr = 1;
newapoint->AreaData.HoldNum = 0;
newapoint->AreaData.HoldDays = 0;
LinkArea(root, newapoint);
root = newapoint;
}
else
root = apoint;
}
/* First group: all private messages */
if (group=strdup(""))
{
UMSMsgNum num=0;
/* Print header */
printf("\nWell, let's do the twist :-) ...\n\n");
/* Set local bit 0 in all messages with NO ViewAccess */
UMSSelectTags(account,UMSTAG_SelWriteLocal, TRUE,
UMSTAG_SelSet, 1,
UMSTAG_SelMask, UMSUSTATF_ViewAccess,
UMSTAG_SelMatch, 0,
TAG_DONE);
/* For all groups */
for (;;)
{
/* Do the work */
/* Set local bit 0 on all messages in message group */
UMSSelectTags(account,UMSTAG_SelWriteLocal, TRUE,
UMSTAG_SelSet, 1,
UMSTAG_SelQuick, TRUE,
UMSTAG_WGroup, group,
TAG_DONE);
if (strlen(group) && (!Pattern || MatchPatternNoCase(DOSPatt, group)))
{
/* Print group name */
printf("UMS Group: \"%s\"\n", group);
group2 = strdup(group);
if (!group2)
{
fprintf(stderr, "Error: out of memory!\n");
free(group);
break;
}
apoint = GroupSearch(group);
if (!apoint || Force)
{
/* No corresponding KMS area found -> create one */
newapoint = NULL;
*group2 = '\0';
mother = root;
for (arg = strtok(group, "."); arg; arg = strtok(NULL, "."))
{
if (strlen(group2))
strcat(group2, ".");
strcat(group2, arg);
apoint = GroupSearch(group2);
if (!apoint)
{
/* Create next KMS area under current mother */
newapoint = InsertArea();
if (!newapoint)
{
fprintf(stderr, "Error: couldn't create new area!\n");
free(group);
free(group2);
break;
}
strncpy(newapoint->AreaData.Name, arg, sizeof(newapoint->AreaData.Name)-1);
newapoint->AreaData.Name[sizeof(newapoint->AreaData.Name)-1] = '\0';
Upper(newapoint->AreaData.Name);
ConvertSpaces(newapoint->AreaData.Name);
strncpy(newapoint->AreaData.Info, group2, sizeof(newapoint->AreaData.Info)-1);
newapoint->AreaData.Info[sizeof(newapoint->AreaData.Info)-1] = '\0';
strncpy(newapoint->AreaData.MBName, group2, sizeof(newapoint->AreaData.MBName)-1);
newapoint->AreaData.MBName[sizeof(newapoint->AreaData.MBName)-1] = '\0';
strcpy(newapoint->AreaData.FilePath, "");
newapoint->AreaData.Type = ATYPE_NEWS;
newapoint->AreaData.ReadLevel = 0;
newapoint->AreaData.WriteLevel = 0;
newapoint->AreaData.EditLevel = 255;
newapoint->AreaData.QuoteStr = 1;
newapoint->AreaData.PQuoteStr = 1;
newapoint->AreaData.ResendStr = 1;
newapoint->AreaData.ForwardStr = 1;
newapoint->AreaData.OriginStr = 1;
newapoint->AreaData.HoldNum = 0;
newapoint->AreaData.HoldDays = 0;
LinkArea(mother, newapoint);
printf(" ! \"%s\" created\n", group2);
mother = newapoint; /* update mother */
}
else
{
printf(" - \"%s\" exists\n", group2);
mother = apoint; /* update mother */
}
}
CreatePath(mother);
if (newapoint)
printf("=> KMS =>: %s\n", PathString);
else
printf("-> KMS ->: %s\n", PathString);
}
else
{
/* Matching KMS area already exists */
CreatePath(apoint);
printf("-> KMS ->: %s\n", PathString);
}
free(group2);
}
free(group);
/* Search a message which has local bit 0 NOT set */
if (!(num = UMSSearchTags(account,UMSTAG_SearchLocal, TRUE,
UMSTAG_SearchMask, 1,
UMSTAG_SearchMatch, 0,
UMSTAG_SearchQuick, TRUE,
TAG_DONE)))
{
/* No message found --> leave loop */
break;
}
/* Get group name */
if (!ReadUMSMsgTags(account,UMSTAG_RMsgNum, num,
UMSTAG_RGroup, &group,
TAG_DONE))
{
/* Print error message and quit */
fprintf(stderr, "Error: ReadUMSMsgTags() failed!\n");
break;
}
/* Copy group name */
if (!(group = strdup(group)))
{
fprintf(stderr, "Error: couldn't copy group name!\n");
FreeUMSMsg(account, num);
break;
}
/* Free UMS message */
FreeUMSMsg(account, num);
}
}
else
fprintf(stderr, "Error: out of memory!\n");
/* Logout */
UMSLogout(account);
WriteAreaList();
Cleanup();
exit(0);
}
///
/*********************************
* Cleanup *
*********************************
* I: --- *
* O: --- *
*********************************/
/// Cleanup
VOID Cleanup(VOID)
{
if (AreaFile)
free(AreaFile);
if (KMSRoot)
free(KMSRoot);
if (Pattern)
free(Pattern);
if (DOSPatt)
free(DOSPatt);
/* Arealiste freigeben */
struct AreaNode *apoint = AreaList.mlh_Head;
while(apoint->Node.mln_Succ)
{
struct AreaNode *nextapoint = apoint->Node.mln_Succ;
Remove((struct Node *)apoint);
FreeMem(apoint, (ULONG)sizeof(struct AreaNode));
apoint = nextapoint;
}
}
///
/****************************
* Parse Arguments *
****************************
* I: --- *
* O: Error: FALSE Ok: TRUE *
****************************/
/// ParseArgs
#define TEMPLATE "FILENAME/A,ROOT/K,PATTERN/K,FORCE/S"
STRPTR HelpTxt = "UMS2KMS 1.0 -*- UMS to KMS Area Converter -*- (c)1994 Thomas Schwarz\n\n" \
"This tool creates a KMS area data file containing an area tree based\n" \
"on the existing groups in your UMS message base. The tree is built\n" \
"according to the UMS group name components which are separated by periods.\n" \
"For example: For the UMS group \"comp.sys.amiga.misc\" UMS2KMS will create\n" \
"the KMS message area \"/COMP/SYS/AMIGA/MISC\".\n\n" \
"Usage:\n\n" \
"FILENAME/A Name of KMS area data file to be read/written/created.\n" \
"ROOT/K Name of KMS root area, the new area tree is to be built\n" \
" in. If not already existent, this area will be created.\n" \
" If no root is given, the new areas are created directly on\n" \
" the uppermost area level.\n" \
"PATTERN/K If given, only for the UMS groups matching this AmigaDOS\n" \
" pattern KMS message areas will be created.\n" \
"FORCE/S Normally no new KMS area is created for an UMS group, if there\n" \
" already exists one assigned to it (but e.g. following an alter-\n" \
" native naming scheme). If this switch is given, KMS areas are\n" \
" created for all UMS groups not pondering about existing areas.\n";
BOOL ParseArgs(VOID)
{
UBYTE n;
ULONG args[4];
BOOL error = FALSE;
struct RDArgs *rargs = NULL;
struct RDArgs *myrdargs = NULL;
for(n = 0; n < 4; n++)
args[n] = 0;
AreaFile = NULL;
KMSRoot = NULL;
Pattern = NULL;
Force = FALSE;
myrdargs = AllocDosObjectTags(DOS_RDARGS, TAG_DONE);
if(!myrdargs)
{
PrintFault(IoErr(), NULL);
return FALSE;
}
myrdargs->RDA_ExtHelp = HelpTxt;
if(!(rargs = (struct RDArgs *)ReadArgs(TEMPLATE, args, myrdargs)))
{
PrintFault(IoErr(), NULL);
FreeDosObject(DOS_RDARGS, myrdargs);
return FALSE;
}
if (args[0]) /* FILENAME/A */
{
AreaFile = strdup((STRPTR)args[0]);
if (!AreaFile)
{
fprintf(stderr, "Error: out of memory.\n");
error = TRUE;
}
}
if (args[1]) /* ROOT/K */
{
KMSRoot = strdup((STRPTR)args[1]);
if (!KMSRoot)
{
fprintf(stderr, "Error: out of memory.\n");
error = TRUE;
}
}
if (args[2]) /* PATTERN/K */
{
Pattern = strdup((STRPTR)args[2]);
if (!Pattern)
{
fprintf(stderr, "Error: out of memory.\n");
error = TRUE;
}
}
if (args[3]) /* FORCE/S */
Force = TRUE;
FreeArgs(rargs);
FreeDosObject(DOS_RDARGS, myrdargs);
if (error)
return FALSE;
return TRUE;
}
///
/*********************************
* Areadatei lesen *
*********************************
* I: --- *
* O: Erfolg TRUE/FALSE *
*********************************/
/// "ReadAreaList"
BOOL ReadAreaList(VOID)
{
struct AreaNode *apoint;
struct Area area;
TEXT buff[LEN_MBNAME+2]; /* MBNAME ist laengstes Element */
FILE *file;
if (!(file = fopen(AreaFile, "r")))
return TRUE;
else
{
while(fgets(buff, LEN_AREANAME+2, file))
{
if (strlen(buff))
buff[strlen(buff)-1] = '\0'; /* Linefeed am Ende entfernen */
if (!(apoint = (struct AreaNode *)AllocMem((ULONG)sizeof(struct AreaNode),MEMF_PUBLIC|MEMF_CLEAR)))
{
fprintf(stderr, "Error: couldn't AllocMem(AreaNode)!\n");
fclose(file);
return FALSE;
}
clrmem(&area, sizeof(struct Area));
strcpy(area.Name, buff);
if (fgets(buff, LEN_AREAINFO+2, file))
{
if (strlen(buff))
buff[strlen(buff)-1] = '\0'; /* Linefeed am Ende entfernen */
strcpy(area.Info, buff);
}
if (fgets(buff, LEN_MBNAME+2, file))
{
if (strlen(buff))
buff[strlen(buff)-1] = '\0';
strcpy(area.MBName, buff);
}
if (fgets(buff, LEN_FILEAREA+2, file))
{
if (strlen(buff))
buff[strlen(buff)-1] = '\0';
strcpy(area.FilePath, buff);
}
if (fgets(buff, LEN_NUMBER+2, file))
area.ID = (UWORD)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.Type = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.ReadLevel = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.WriteLevel = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.EditLevel = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.AccessBits = (ULONG)atol(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.WriteFlag = (UWORD)atol(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.QuoteStr = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.PQuoteStr = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.ResendStr = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.ForwardStr = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.OriginStr = (UBYTE)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.HoldNum = (UWORD)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.HoldDays = (UWORD)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.Mother = (UWORD)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.Daughter = (UWORD)atoi(buff);
if (fgets(buff, LEN_NUMBER+2, file))
area.Next = (UWORD)atoi(buff);
apoint->AreaData = area;
AddTail((struct List *)&AreaList, (struct Node *)apoint);
}
fclose(file);
}
return TRUE;
}
///
/*********************************
* Areadatei schreiben *
*********************************
* I: --- *
* O: Erfolg TRUE/FALSE *
*********************************/
/// "WriteAreaList"
BOOL WriteAreaList(VOID)
{
struct AreaNode *apoint;
FILE *file;
file = fopen(AreaFile, "w");
if (!file)
{
fprintf(stderr, "Error: couldn't write to %s!\n", AreaFile);
return FALSE;
}
apoint = (struct AreaNode *)AreaList.mlh_Head;
while(apoint->Node.mln_Succ)
{
fprintf(file,"%s\n%s\n%s\n%s\n", apoint->AreaData.Name,
apoint->AreaData.Info,
apoint->AreaData.MBName,
apoint->AreaData.FilePath);
fprintf(file,"%d\n%d\n%d\n%d\n%d\n", apoint->AreaData.ID,
apoint->AreaData.Type,
apoint->AreaData.ReadLevel,
apoint->AreaData.WriteLevel,
apoint->AreaData.EditLevel);
fprintf(file,"%ld\n%d\n", apoint->AreaData.AccessBits,
apoint->AreaData.WriteFlag);
fprintf(file,"%d\n%d\n%d\n%d\n%d\n", apoint->AreaData.QuoteStr,
apoint->AreaData.PQuoteStr,
apoint->AreaData.ResendStr,
apoint->AreaData.ForwardStr,
apoint->AreaData.OriginStr);
fprintf(file,"%d\n", apoint->AreaData.HoldNum);
fprintf(file,"%d\n", apoint->AreaData.HoldDays);
fprintf(file,"%d\n%d\n%d\n", apoint->AreaData.Mother,
apoint->AreaData.Daughter,
apoint->AreaData.Next);
apoint = apoint->Node.mln_Succ;
}
fclose(file);
return TRUE;
}
///
/*******************************************
* UMS-MsgBase-Namen global suchen *
*******************************************
* I: gesuchte Area *
* O: AreaNode *
*******************************************/
/// "GroupSearch"
struct AreaNode *GroupSearch(STRPTR name)
{
struct AreaNode *apoint;
apoint = (struct AreaNode *)AreaList.mlh_Head;
while(apoint->Node.mln_Succ)
{
if (!stricmp(name, apoint->AreaData.MBName))
return apoint;
apoint = apoint->Node.mln_Succ;
}
return NULL;
}
///
/*******************************************
* KMS-Area auf erster Ebene suchen *
*******************************************
* I: gesuchte Area *
* O: AreaNode *
*******************************************/
/// AreaSearch
struct AreaNode *AreaSearch(STRPTR name)
{
struct AreaNode *apoint;
apoint = SetArea(1);
if (!apoint)
return NULL;
apoint = SetArea(apoint->AreaData.Daughter);
while (apoint)
{
if (!stricmp(apoint->AreaData.Name, name))
return apoint;
apoint = SetArea(apoint->AreaData.Next);
}
return NULL;
}
///
/***************************************
* Pfad-String konstruieren *
***************************************
* I: struct AreaNode * *
* O: --- *
***************************************/
/// "CreatePath"
VOID CreatePath(struct AreaNode *area)
{
struct AreaNode *apoint;
TEXT merk[LEN_KMSPATH+1];
if (!area)
{
*PathString = '\0';
return;
}
/* Pfad-String konstruieren */
strcpy(PathString, area->AreaData.Name);
apoint = area;
while(apoint && apoint->AreaData.Mother && strlen(PathString) < LEN_KMSPATH)
{
apoint = SetArea(apoint->AreaData.Mother);
strcpy(merk, PathString);
if (apoint && apoint->AreaData.Mother)
strcpy(PathString, apoint->AreaData.Name);
else
strcpy(PathString, "");
strcat(PathString, "/");
strncat(PathString, merk, LEN_KMSPATH - strlen(merk));
PathString[LEN_KMSPATH] = '\0';
}
}
///
/********************************
* Area in Liste suchen *
********************************
* I: Area-Index *
* O: struct AreaNode * *
********************************/
/// "SetArea"
struct AreaNode *SetArea(UWORD idx)
{
struct AreaNode *apoint;
if (!idx)
return NULL;
apoint = (struct AreaNode *)AreaList.mlh_Head;
if (apoint->Node.mln_Succ)
{
while(apoint->Node.mln_Succ && apoint->AreaData.ID != idx)
apoint = (struct AreaNode *)apoint->Node.mln_Succ;
if (apoint->Node.mln_Succ)
return apoint;
else
return NULL;
}
else
return NULL;
}
///
/********************************
* Neue Areastruktur einrichten *
********************************
* I: --- *
* O: struct AreaNode * *
********************************/
/// InsertArea
struct AreaNode *InsertArea(VOID)
{
struct AreaNode *apoint, *newapoint;
UWORD id = 0, previd = 0;
apoint = (struct AreaNode *)AreaList.mlh_TailPred;
if (!apoint->Node.mln_Pred)
{
/* Sonderfall: Erster Listeneintrag */
if (!(newapoint = (struct AreaNode *)AllocMem((ULONG)sizeof(struct AreaNode),MEMF_PUBLIC|MEMF_CLEAR)))
return NULL;
newapoint->AreaData.ID = 1;
AddTail((struct List *)&AreaList, (struct Node *)newapoint);
return newapoint;
}
/* Größte ID suchen */
apoint = (struct AreaNode *)AreaList.mlh_Head;
while(apoint->Node.mln_Succ)
{
if (apoint->AreaData.ID > previd)
previd = apoint->AreaData.ID;
apoint = apoint->Node.mln_Succ;
}
if (previd + 1 == 0) /* ID-Überlauf */
{
previd = 0; id = 0;
apoint = (struct AreaNode *)AreaList.mlh_Head;
id = apoint->AreaData.ID;
while(apoint->Node.mln_Succ && previd + 1 == id)
{
previd = id;
apoint = (struct AreaNode *)apoint->Node.mln_Succ;
if (apoint->Node.mln_Succ)
id = apoint->AreaData.ID;
}
}
if (previd == id)
return NULL;
if (!(newapoint = (struct AreaNode *)AllocMem((ULONG)sizeof(struct AreaNode),MEMF_PUBLIC|MEMF_CLEAR)))
return NULL;
newapoint->AreaData.ID = previd + 1;
Insert((struct List *)&AreaList, (struct Node *)newapoint, (struct Node *)apoint->Node.mln_Pred);
return newapoint;
}
///
/********************************
* String -> Großbuchstaben *
********************************
* I: STRPTR *
* O: --- *
********************************/
/// Upper
VOID Upper(STRPTR string)
{
if(!string)
return;
while(*string)
{
*string = toupper(*string);
string++;
}
}
///
/********************************
* String -> Kleinbuchstaben *
********************************
* I: STRPTR *
* O: --- *
********************************/
/// Lower
VOID Lower(STRPTR string)
{
if(!string)
return;
while(*string)
{
*string = tolower(*string);
string++;
}
}
///
/********************************
* Leerzeichen -> "-" *
********************************
* I: STRPTR *
* O: --- *
********************************/
/// ConvertSpaces
VOID ConvertSpaces(STRPTR string)
{
if(!string)
return;
while(*string)
{
if (*string == ' ')
*string = '-';
string++;
}
}
///
/********************************
* Neue Area einhängen *
********************************
* I: AreaNode *mother, *new *
* O: --- *
********************************/
/// LinkArea
VOID LinkArea(struct AreaNode *mother, struct AreaNode *newan)
{
if(!mother->AreaData.Daughter)
{
/* Neue erste Tochter */
mother->AreaData.Daughter = newan->AreaData.ID;
newan->AreaData.Mother = mother->AreaData.ID;
newan->AreaData.Next = 0;
}
else
{
/* Weitere Tochter einsortieren */
struct AreaNode *daughter, *predaughter;
daughter = SetArea(mother->AreaData.Daughter);
predaughter = NULL;
/* Alphabetisch einsortieren */
while(daughter && stricmp(newan->AreaData.Name, daughter->AreaData.Name) != -1)
{
predaughter = daughter;
if(daughter->AreaData.Next)
daughter = SetArea(daughter->AreaData.Next);
else
daughter = NULL;
}
newan->AreaData.Mother = mother->AreaData.ID;
if(!predaughter)
{
/* Neue Area ist die erste */
newan->AreaData.Next = daughter->AreaData.ID;
mother->AreaData.Daughter = newan->AreaData.ID;
}
else if(!daughter)
{
/* Neue Area ist die letzte */
predaughter->AreaData.Next = newan->AreaData.ID;
newan->AreaData.Next = 0;
}
else
{
/* Neue Area zwischen predaughter und daughter einhängen */
predaughter->AreaData.Next = newan->AreaData.ID;
newan->AreaData.Next = daughter->AreaData.ID;
}
}
}
///